Early Preview

This is currently very much a preview. Please feel free to try things out, but don't be upset if anything is not yet working. Feedback is welcome over on our GitHub Dicussions page.

class System.​Runtime.​CompilerServices.​ConditionalWeakTable<​TKey, TValue>

Assembly: System.Runtime

Inheritance: object → ConditionalWeakTable

Implemented Interfaces

Enables compilers to dynamically attach object fields to managed objects.

Methods

public void
Add​(TKey key, TValue value)
Adds a key to the table.
key The key to add. <paramref name="key" /> represents the object to which the property is attached.
value The key's property value.
public void
AddOrUpdate​(TKey key, TValue value)
Adds the key and value if the key doesn't exist, or updates the existing key's value if it does exist.
key The key to add or update. May not be <see langword="null" /> .
value The value to associate with <paramref name="key" /> .
public void
Clear​()
Clears all the key/value pairs.
public TValue
GetOrAdd​(TKey key, TValue value)
<para>Searches for a specified key in the table and returns the corresponding value. If the key does not exist in the table, the method adds the given value and binds it to the specified key.</para>
Returns The value bound to <typeparamref name="TKey" /> in the current <see cref="T:System.Runtime.CompilerServices.ConditionalWeakTable`2" /> instance, after the method completes.
key The key of the value to find. It cannot be <see langword="null" /> .
value The value to add and bind to <typeparamref name="TKey" /> , if one does not exist already.
public TValue
GetOrAdd​(TKey key, Func<​TKey, TValue> valueFactory)
<para>Searches for a specified key in the table and returns the corresponding value. If the key does not exist in the table, the method invokes the supplied factory to create a value that is bound to the specified key.</para>
Returns The value bound to <typeparamref name="TKey" /> in the current <see cref="T:System.Runtime.CompilerServices.ConditionalWeakTable`2" /> instance, after the method completes.
key The key of the value to find. It cannot be <see langword="null" /> .
valueFactory The callback that creates a value for key, if one does not exist already. It cannot be <see langword="null" /> .
public TValue
GetOrAdd​(TKey key, Func<​TKey, TArg, TValue> valueFactory, TArg factoryArgument)
<para>Searches for a specified key in the table and returns the corresponding value. If the key does not exist in the table, the method invokes the supplied factory to create a value that is bound to the specified key.</para>
Returns The value bound to <typeparamref name="TKey" /> in the current <see cref="T:System.Runtime.CompilerServices.ConditionalWeakTable`2" /> instance, after the method completes.
key The key of the value to find. It cannot be <see langword="null" /> .
valueFactory The callback that creates a value for key, if one does not exist already. It cannot be <see langword="null" /> .
factoryArgument The additional argument to supply to <paramref name="valueFactory" /> upon invocation.
public TValue
GetOrCreateValue​(TKey key)
Atomically searches for a specified key in the table and returns the corresponding value. If the key does not exist in the table, the method invokes the parameterless constructor of the class that represents the table's value to create a value that is bound to the specified key.
Returns The value that corresponds to <paramref name="key" /> , if <paramref name="key" /> already exists in the table; otherwise, a new value created by the parameterless constructor of the class defined by the <paramref name="TValue" /> generic type parameter.
key The key to search for. <paramref name="key" /> represents the object to which the property is attached.
public TValue
GetValue​(TKey key, CreateValueCallback<​TKey, TValue> createValueCallback)
public bool
Remove​(TKey key)
Removes a key and its value from the table.
Returns <see langword="true" /> if the key is found and removed; otherwise, <see langword="false" /> .
key The key to remove.
public bool
Remove​(TKey key, TValue& value)
public bool
TryAdd​(TKey key, TValue value)
Adds a key to the table if it doesn't already exist.
Returns <see langword="true" /> if the key/value pair was added; <see langword="false" /> if the table already contained the key.
key The key to add.
value The key's property value.
public bool
TryGetValue​(TKey key, TValue& value)
public bool
Equals​(object obj)
Inherited from object
Determines whether the specified object is equal to the current object.
Returns <see langword="true" /> if the specified object is equal to the current object; otherwise, <see langword="false" /> .
obj The object to compare with the current object.
protected void
Finalize​()
Inherited from object
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
public int
GetHashCode​()
Inherited from object
Serves as the default hash function.
Returns A hash code for the current object.
public Type
GetType​()
Inherited from object
Gets the <see cref="T:System.Type" /> of the current instance.
Returns The exact runtime type of the current instance.
protected object
MemberwiseClone​()
Inherited from object
Creates a shallow copy of the current <see cref="T:System.Object" /> .
Returns A shallow copy of the current <see cref="T:System.Object" /> .
public string
ToString​()
Inherited from object
Returns a string that represents the current object.
Returns A string that represents the current object.